﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetfractionHub.LocalMachine.BotCommands
{
    public abstract class CommandHandler
    {
        private BotNode _parentBot;

        public BotNode ParentBot
        {
            get { return _parentBot; }
            set { _parentBot = value; }
        }

        public virtual BotReturnStatus HandleCommandMessage(RemoteMachine.Node node, CommandMessage message)
        {
            return new BotReturnStatus(false);
        }

        protected bool CheckArgumentMix(CommandMessage message, int totalArguments)
        {
            return message.ArgumentsCount == totalArguments;
        }

        protected bool CheckArgumentMix(CommandMessage message, int stringArguments, int booleanArguments, int unnamedArguments)
        {
            return (message.StringArguments.Count == stringArguments) && (message.BooleanArguments.Count == booleanArguments) && (message.UnnamedArguments.Count == unnamedArguments);
        }

        protected bool SetVariableToStringArgument(CommandMessage message, string argumentKey, out string value)
        {
            value = string.Empty;
            if (!message.StringArguments.ContainsKey(argumentKey))
                return false;

            if (string.IsNullOrEmpty(message.StringArguments[argumentKey]))
                return false;

            value = message.StringArguments[argumentKey];
            return true;
        }
    }

    [global::System.AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
    public sealed class CommandHandlerAttribute : Attribute
    {
        private string _trigger;
        private string _triggerAlias;
        private string _description;

        public CommandHandlerAttribute(string trigger)
        {
            this._trigger = trigger;
            _triggerAlias = string.Empty;
            _description = string.Empty;
        }

        public string Trigger
        {
            get { return _trigger; }
        }

        public string Description
        {
            get { return _description; }
            set { _description = value; }
        }

        public string TriggerAlias
        {
            get { return _triggerAlias; }
            set { _triggerAlias = value; }
        }
    }
}
